/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.workflow;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.modules.ivm.entity.workflow.WorkFlow;
import com.neusoft.lohas.modules.ivm.dao.workflow.WorkFlowDao;

/**
 * 流程Service
 * @author Jackie.Liu
 * @version 2014-12-21
 */
@Component
@Transactional(readOnly = true)
public class WorkFlowService extends BaseService {

	@Autowired
	private WorkFlowDao workFlowDao;
	
	public WorkFlow get(String id) {
		return workFlowDao.get(id);
	}
	
	public Page<WorkFlow> find(Page<WorkFlow> page, WorkFlow workFlow) {
		DetachedCriteria dc = workFlowDao.createDetachedCriteria();
		dc.add(Restrictions.eq(WorkFlow.FIELD_DEL_FLAG, WorkFlow.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return workFlowDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(WorkFlow workFlow) {
		workFlowDao.save(workFlow);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		workFlowDao.deleteById(id);
	}

	public WorkFlow findByOrderId(String orderId) {
		WorkFlow workFlow = new WorkFlow();
		workFlow = workFlowDao.findByOrderId(orderId);
		return workFlow;
	}

	@Transactional(readOnly = false)
	public int updateStatusById(String id, String status) {
		return workFlowDao.updateStatusById(id, status);
	}
	
	@Transactional(readOnly = false)
	public void deleteWorkFlowById(String id) {
		workFlowDao.deleteWorkFlowById(id);
	}
	
}
